import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    name:"login",
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/callback',
    name:"callback",
    component: () => import('@/views/login/callback'),
    hidden: true
  },
  {
    path: '/silentRenew',
    name:"silentRenew",
    component: () => import('@/views/login/silentRenew'),
    hidden: true
  },
  {
    path: '/404',
    name:'404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/401',
    name:'401',
    component: () => import('@/views/401'),
    hidden: true
  }, 
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'home',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'icon-shouye' }
    }]
  },
   {
    path: '/article',
    component: Layout,
    children: [ {
        "path": "/articles",
        "name": "articles",
        component: () => import('@/views/articles/index'),
        "meta": {
            "title": "文章管理",
            "icon": "icon-shezhi"
        }
    }]
  },
  {
    path: '/user',
    component: Layout,
    children: [{
        "path": "/users",
        "name": "users",
        component: () => import('@/views/User/index'),
        "meta": {
            "title": "用户管理",
            "icon": "icon-shezhi"
        }
    }]
  },
  {
    path: '/brand',
    component: Layout,
    children: [{
        "path": "/brands",
        "name": "brands",
        component: () => import('@/views/brands/index'),
        "meta": {
            "title": "品牌管理",
            "icon": "icon-shezhi"
        }
    }]
  },
  {
    path: '/category',
    component: Layout,
    children: [{
        "path": "/categories",
        "name": "categories",
        component: () => import('@/views/categories/index'),
        "meta": {
            "title": "分类管理",
            "icon": "icon-shezhi"
        }
    }]
  },
  {
    path: '/product',
    component: Layout,
    children: [{
        "path": "/products",
        "name": "products",
        component: () => import('@/views/products/index'),
        "meta": {
            "title": "商品管理",
            "icon": "icon-shezhi"
        }
    }]
  },
  {
    path: '/language',
    component: Layout,
    children: [{
        "path": "/languages",
        "name": "languages",
        component: () => import('@/views/languages/index'),
        "meta": {
            "title": "语言管理",
            "icon": "icon-shezhi"
        }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => new Router({
  mode: 'hash', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
